﻿using Method.Token;
using RedisHelper.LogIn;
using System;
using System.Collections.Generic;
using System.Text;

namespace Method.DAL
{
    /// <summary>
    /// 获取用户Id 由 令牌
    /// </summary>
    public class GetUidByToken
    {
        /// <summary>
        /// 获取用户编号
        /// </summary>
        /// <param name="token">用户令牌</param>
        /// <returns>返回不是null则是登录状态, 否则需要重新登录</returns>
        public string GetUid(string token)
        {
            //获取当前令牌的私钥
            var sessionId = new UserLogIn().IsTokenExist(token);
            if (sessionId is null)
                return null;
            //解密
            var uid = JwtOperating.SelectJwt(token, sessionId);
            return uid;
        }
    }
}
